//
//  FlutterDataUtils.swift
//  ble_printer
//
//  Created by ivic-flm on 2021/6/8.
//

import Foundation

enum EventType:Int {
    case BLE_FOUND = 1
    case BLE_CONNECTED = 2
    case BLE_CONNECTE_FAILED = 3
    case BLE_DISCONNECTED = 4
    case BLE_CONNECTE_NODEVICE = 5
    case BLE_ENABLE = 8
    case BLE_DISABLE = 9
}

class FlutterDataUtils:NSObject {
    
    static let share: FlutterDataUtils = {
        let instance = FlutterDataUtils.init()
        
        return instance
    }()
    
    func sendEvent<T: Codable>(type:Int,data:T ,ret:Int = 1) {
        var retData = FlutterData.RetData<T>()
        retData.ret = ret
        retData.type = type
        retData.data = data
        let d = JsonUtils.toJsony(model: retData)
        SwiftBlePrinterPlugin().sendEvent(params: d)
    }
}

class FlutterData {
    
    struct RetData<T:Codable>:Codable {
        var type: Int? = -1  //返回类型
        var ret: Int = 1 //返回结果
        var data: T?  //返回数据
    }
    
    struct BleDevice:Codable {
        var name: String? = ""
        var mac: String? = ""
        var bound: Int? = 0
        var per: Int? = 0
    }
    
    struct PrinterTicketData:Codable {
        var company: String? = ""
        var addressStart: String? = ""
        var addressEnd: String? = ""
        var carNum: String? = ""
        var driverName: String? = ""
        var ticketTime: String? = ""
        var ticketUser: String? = ""
        var ticketId: String? = ""
        var ticketTimes: String? = ""
        var ticketBarCode: String? = ""
        var ticketQrCode: String? = ""
    }
}
